//
//  MLHorizontalFlowLayout.m
//  MLHorizontalView
//
//  Created by molon on 14/12/31.
//  Copyright (c) 2014年 molon. All rights reserved.
//

#import "MLSingleRowHorizontalFlowLayout.h"

@interface MLSingleRowHorizontalFlowLayout()

@end

@implementation MLSingleRowHorizontalFlowLayout

-(id)init
{
    self = [super init];
    if (self) {
        self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        self.minimumLineSpacing = 0.0f;
        self.minimumInteritemSpacing = 0.0f;
        self.sectionInset = UIEdgeInsetsZero;
        self.itemSize = CGSizeMake(1, 1);
    }
    return self;
}

-(void)prepareLayout
{
    [self updateItemSize];
    
    [super prepareLayout];
}

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
    CGSize oldSize = self.collectionView.bounds.size;
    if (!CGSizeEqualToSize(oldSize, newBounds.size)) {
        return YES;
    }
    
    return NO;
}

#pragma mark - helper
- (void)updateItemSize
{
    CGSize itemSize = self.collectionView.frame.size;
    itemSize.height = fmax(1,itemSize.height-(self.collectionView.contentInset.top+self.collectionView.contentInset.bottom)-(self.sectionInset.top+self.sectionInset.bottom));
    itemSize.width = fmax(1, itemSize.width);
    
    self.itemSize = itemSize;
}

@end
